<template>
  <div class="home-container">
    <!-- 欢迎横幅 -->
    <div class="welcome-banner">
      <div class="welcome-content">
        <div class="welcome-text">
          <h1>欢迎回来，{{ username }}！</h1>
          <p>今天是 {{ currentDate }}，祝您生意兴隆！</p>
        </div>
        <div class="welcome-illustration">
          <el-icon class="restaurant-icon"><Food /></el-icon>
        </div>
      </div>
    </div>

    <!-- 数据统计卡片 -->
    <div class="stats-section">
      <el-row :gutter="20">
        <el-col :xs="24" :sm="12" :md="6">
          <el-card class="stats-card total-dishes">
            <div class="stats-content">
              <div class="stats-icon">
                <el-icon><Bowl /></el-icon>
              </div>
              <div class="stats-info">
                <div class="stats-number">{{ todayStats.dishes }}</div>
                <div class="stats-label">菜品数量</div>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="12" :md="6">
          <el-card class="stats-card customer-rating">
            <div class="stats-content">
              <div class="stats-icon">
                <el-icon><Star /></el-icon>
              </div>
              <div class="stats-info">
                <div class="stats-number">{{ todayStats.rating }}<span class="rating-text">/5.0</span></div>
                <div class="stats-label">顾客评分</div>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="12" :md="6">
          <el-card class="stats-card member-count">
            <div class="stats-content">
              <div class="stats-icon">
                <el-icon><User /></el-icon>
              </div>
              <div class="stats-info">
                <div class="stats-number">{{ todayStats.members }}</div>
                <div class="stats-label">会员数量</div>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :sm="12" :md="6">
          <el-card class="stats-card online-status">
            <div class="stats-content">
              <div class="stats-icon">
                <el-icon><CircleCheck /></el-icon>
              </div>
              <div class="stats-info">
                <div class="stats-number">营业中</div>
                <div class="stats-label">营业状态</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 温馨提示区域 -->
    <div class="tips-section">
      <el-row :gutter="20">
        <el-col :xs="24" :md="12">
          <el-card class="tips-card">
            <template #header>
              <div class="card-header">
                <el-icon class="tip-icon"><InfoFilled /></el-icon>
                <span>营业小贴士</span>
              </div>
            </template>
            <div class="tips-content">
              <div class="tip-item" v-for="tip in businessTips" :key="tip.id">
                <el-icon class="tip-bullet"><Check /></el-icon>
                <span>{{ tip.text }}</span>
              </div>
            </div>
          </el-card>
        </el-col>
        
        <el-col :xs="24" :md="12">
          <el-card class="tips-card">
            <template #header>
              <div class="card-header">
                <el-icon class="tip-icon"><CircleCheck /></el-icon>
                <span>美好祝福</span>
              </div>
            </template>
            <div class="blessing-content">
              <div class="blessing-text">
                <p>{{ currentBlessing }}</p>
              </div>
              <div class="blessing-decoration">
                <el-icon class="decoration-icon"><Present /></el-icon>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 快捷操作区域 -->
    <div class="quick-actions">
      <h3>快捷操作</h3>
      <el-row :gutter="15">
        <el-col :xs="12" :sm="8" :md="4" v-for="action in quickActions" :key="action.name">
          <div class="action-item" @click="handleQuickAction(action.route)">
            <div class="action-icon">
              <el-icon><component :is="action.icon" /></el-icon>
            </div>
            <div class="action-text">{{ action.name }}</div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import {
  Food,
  Bowl,
  Star,
  User,
  CircleCheck,
  InfoFilled,
  Check,
  Present,
  Plus,
  Setting,
  DataBoard,
  Document
} from '@element-plus/icons-vue'

const router = useRouter()

const username = ref('张三')

const currentDate = computed(() => {
  const now = new Date()
  const year = now.getFullYear()
  const month = now.getMonth() + 1
  const day = now.getDate()
  const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  const weekDay = weekDays[now.getDay()]
  return `${year}年${month}月${day}日 ${weekDay}`
})

// 模拟今日统计数据
const todayStats = ref({
  dishes: 56,
  rating: 4.8,
  members: 286
})

// 营业小贴士
const businessTips = ref([
  { id: 1, text: '保持菜品新鲜，定期检查食材质量' },
  { id: 2, text: '及时响应顾客需求，提升服务体验' },
  { id: 3, text: '合理调整菜品价格，增加利润空间' },
  { id: 4, text: '关注用户评价，持续改进菜品口味' },
  { id: 5, text: '定期更新菜单，推出特色新品' }
])

// 美好祝福语
const blessings = [
  '愿您的餐厅生意红红火火，顾客满堂！',
  '美味佳肴传千里，宾客如云笑开怀！',
  '食客盈门财源广，口碑相传生意兴！',
  '精心烹饪每一道菜，用心服务每一位客！',
  '愿您的餐厅成为这座城市最温暖的地方！'
]

const currentBlessing = computed(() => {
  const index = new Date().getDate() % blessings.length
  return blessings[index]
})

// 快捷操作
const quickActions = ref([
  { name: '添加菜品', route: '/dashboard/dishes', icon: 'Plus' },
  { name: '订单管理', route: '/dashboard/orders', icon: 'Document' },
  { name: '收益分析', route: '/dashboard/revenue-analysis', icon: 'DataBoard' },
  { name: '会员管理', route: '/dashboard/members', icon: 'User' },
  { name: '商家设置', route: '/dashboard/store-name', icon: 'Setting' },
  { name: 'WiFi设置', route: '/dashboard/wifi-settings', icon: 'Setting' }
])

const handleQuickAction = (route: string) => {
  router.push(route)
}

onMounted(() => {
  // 从本地存储获取用户名
  const storedUsername = localStorage.getItem('username')
  if (storedUsername) {
    username.value = storedUsername
  }
})
</script>

<style scoped>
.home-container {
  max-width: 1200px;
  margin: 0 auto;
}

/* 欢迎横幅 */
.welcome-banner {
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  border-radius: 16px;
  padding: 30px;
  margin-bottom: 24px;
  color: white;
  position: relative;
  overflow: hidden;
}

.welcome-banner::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: rotate 20s linear infinite;
}

.welcome-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 1;
}

.welcome-text h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px 0;
}

.welcome-text p {
  font-size: 16px;
  opacity: 0.9;
  margin: 0;
}

.restaurant-icon {
  font-size: 64px;
  opacity: 0.7;
}

/* 统计卡片 */
.stats-section {
  margin-bottom: 24px;
}

.stats-card {
  border-radius: 12px;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  margin-bottom: 16px;
  transition: transform 0.3s ease;
}

.stats-card:hover {
  transform: translateY(-2px);
}

.stats-content {
  display: flex;
  align-items: center;
  padding: 8px 0;
}

.stats-icon {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 24px;
}

.total-dishes .stats-icon {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: white;
}

.customer-rating .stats-icon {
  background: linear-gradient(135deg, #43e97b, #38f9d7);
  color: white;
}

.member-count .stats-icon {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.online-status .stats-icon {
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: white;
}

.stats-info {
  flex: 1;
}

.stats-number {
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  line-height: 1;
}

.rating-text {
  font-size: 14px;
  color: #909399;
}

.stats-label {
  font-size: 14px;
  color: #606266;
  margin-top: 4px;
}

/* 提示区域 */
.tips-section {
  margin-bottom: 24px;
}

.tips-card {
  border-radius: 12px;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  margin-bottom: 16px;
  height: 300px;
}

.card-header {
  display: flex;
  align-items: center;
  font-weight: 600;
  color: #303133;
}

.tip-icon {
  margin-right: 8px;
  color: #409eff;
}

.tips-content {
  height: 200px;
  overflow-y: auto;
}

.tip-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 12px;
  line-height: 1.6;
}

.tip-bullet {
  color: #67c23a;
  margin-right: 8px;
  margin-top: 2px;
  flex-shrink: 0;
}

.blessing-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 200px;
}

.blessing-text {
  flex: 1;
  font-size: 16px;
  line-height: 1.8;
  color: #606266;
}

.blessing-decoration {
  margin-left: 20px;
}

.decoration-icon {
  font-size: 48px;
  color: #f56c6c;
  opacity: 0.7;
}

/* 快捷操作 */
.quick-actions {
  margin-bottom: 24px;
}

.quick-actions h3 {
  margin: 0 0 16px 0;
  color: #303133;
  font-size: 18px;
  font-weight: 600;
}

.action-item {
  background: white;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 12px;
}

.action-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.action-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px auto;
  font-size: 20px;
}

.action-text {
  font-size: 14px;
  color: #303133;
  font-weight: 500;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .welcome-content {
    flex-direction: column;
    text-align: center;
  }
  
  .restaurant-icon {
    margin-top: 16px;
  }
  
  .welcome-text h1 {
    font-size: 24px;
  }
  
  .blessing-content {
    flex-direction: column;
    text-align: center;
  }
  
  .blessing-decoration {
    margin: 16px 0 0 0;
  }
}
</style> 